import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './style/index.less'
import './style/iconfont.css'
import 'lib-flexible'
import moment from 'moment'
import { Field, Toast, Cell, CellGroup, Dialog, RadioGroup, Radio, Uploader, Button, List, Tab, Tabs } from 'vant'
import { PullRefresh } from 'vant';
import { Sticky } from 'vant';
import { Icon } from 'vant';

Vue.use(Icon);
Vue.use(Sticky);
Vue.use(PullRefresh);
Vue.use(Field);
Vue.use(Toast);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Dialog);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Uploader);
Vue.use(Button);
Vue.use(List);
Vue.use(Tab);
Vue.use(Tabs);


Vue.filter('date', (value, format = 'YYYY-MM-DD') => {
  return moment(value).format(format)
})
import axios from 'axios'
axios.defaults.baseURL = 'http://localhost:3000'
Vue.prototype.$axios = axios
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  const token = localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }

  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
// axios.interceptors.response.use(function (response) {
//   // 对响应数据做点什么
//   const { statusCode, message } = response.data
//   if (statusCode == 401 && message == '用户信息验证失败') {
//     localStorage.removeItem('token')
//     localStorage.removeItem('id')
//     router.push('/login')
//   }
//   return response;
// }, function (error) {
//   // 对响应错误做点什么
//   return Promise.reject(error);
// });

import Head from './components/Head.vue'
import Logo from './components/Logo.vue'
import Buttons from './components/Botton.vue'
import MyLove from './components/MyLove.vue'
import MyHead from './components/MyHead.vue'
import Comment from './components/Comment.vue'
Vue.config.productionTip = false
Vue.component('head-title', Head)
Vue.component('logo', Logo)
Vue.component('shop-button', Buttons)
Vue.component('mylove', MyLove)
Vue.component('myhead', MyHead)
Vue.component('comment', Comment)

const bus = new Vue()
Vue.prototype.$bus = bus

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
